#include "sqstack.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

sqstack * list_create(int length)
{
    sqstack * p = (sqstack *)malloc(sizeof(sqstack));
    if (NULL == p)
    {
        puts("malloc failed.");
        return NULL;
    }

    p->data = (data_t *)malloc(length * sizeof(data_t));
    if (p->data == NULL)
    {
        puts("data malloc failed.");
        return NULL;
    }

    p->top = -1;
    p->maxLen = length;
    memset(p->data, 0, length * sizeof(data_t));

    return p;
}

int list_push(sqstack * p, data_t value)
{
    if (NULL == p) return -1;
    if (p->top == p->maxLen - 1)
    {
        puts("Sequence list is full.");
        return -1;
    }
    p->data[++p->top] = value;

    return 0;
}

int list_show(sqstack * p)
{
    int i;
    if (NULL == p) return -1;
    if (p->top == -1)
    {
        puts("Sequence list is empty.");
        return -1;
    }

    for (i = p->top; i >= 0; i--)
    {
        printf("%d ", p->data[i]);
    }
    puts("");

    return 0;    
}